﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using model;
using System.Data;
using System.Data.SqlClient;

namespace dao
{
    public class ImageDao:BaseDao
    {
        public List<Image> getListImageBySanpham(long id)
        {
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.CommandText = "sp_Image_BySanpham";
            sqlCmd.Parameters.Clear();
            sqlCmd.Parameters.Add("@IDSanpham", SqlDbType.BigInt).Value = id;
            sqlCmd.Connection.Close();
            sqlCmd.Connection.Open();

            using (SqlDataReader dr = sqlCmd.ExecuteReader())
            {
                List<Image> glstImage = new List<Image>();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        Image im = new Image();
                        im.ID = Convert.ToInt64(dr["ID"]);
                        im.IDSanpham = Convert.ToInt64(dr["IDSanpham"]);
                        im.Duongdan = Convert.ToString(dr["Duongdan"]);
                        
                        glstImage.Add(im);
                    }
                    dr.Close();
                    sqlCmd.Connection.Close();
                }
                return glstImage;
            }
        }
    }
}
